package com.stoneframe.util.baseSpring;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * 普通类调用Spring注解方式的Service层bean
 */
@Component
public class SpringBeanFactoryUtils implements ApplicationContextAware {
	
	private static ApplicationContext appContext;

	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		// TODO Auto-generated method stub
		appContext=applicationContext;
	}
	
	/**
     * 获取ApplicationContext
     */
	public static ApplicationContext getApplicationContext(){
		return appContext;
	}
	
	/**
     * 这是一个便利的方法，帮助我们快速得到一个BEAN
     */
	public static Object getBean(String beanName){
		return appContext.getBean(beanName);
	}

}
